package com.linkhub.oms.admin.modules.order.domain.dto;

import cn.hutool.core.util.IdUtil;
import com.linkhub.oms.common.enums.mp.DataStatusEnum;
import com.linkhub.oms.common.enums.mp.DocumentTypeEnum;
import com.linkhub.oms.common.enums.mp.ExpenseTypeEnum;
import com.linkhub.oms.common.enums.mp.FreezeStatusEnum;
import com.linkhub.oms.common.enums.mp.TransactionTypeEnum;
import com.linkhub.oms.entity.UserAccountFlowEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @Description: OrderFulfillmentExpenseDTO
 * @Author: echo
 * @Date: 2024/6/2 14:26
 * @Version: 1.0
 */
@Data
public class OrderFulfillmentExpenseDTO implements Serializable {

    private String sysOrderId;

    /**
     * estimatedFreight
     */
    private BigDecimal estimatedFreight;

    /**
     * operatingCharge
     */
    private BigDecimal operatingCharge;

    @ApiModelProperty(value = "对外挂号费")
    private BigDecimal registrationFreight;

    @ApiModelProperty(value = "VAT增值税")
    private BigDecimal vat;

    @ApiModelProperty(value = "shipo手续费")
    private BigDecimal handlingFee;

    private UserAccountFlowEntity createOrderFreezeAccountFlow(String userId, BigDecimal remainingBalance) {
        UserAccountFlowEntity accountFlow = new UserAccountFlowEntity();

        accountFlow.setUserId(userId);
        accountFlow.setTransactionId(IdUtil.getSnowflake().nextIdStr());
        accountFlow.setTransactionType(TransactionTypeEnum.FREEZE);
        accountFlow.setUnfreezeStatus(FreezeStatusEnum.FREEZE);
        accountFlow.setDocumentId(this.getSysOrderId());
        accountFlow.setDocumentType(DocumentTypeEnum.ORDER);
        accountFlow.setRemainingBalance(remainingBalance);
        accountFlow.setDataStatus(DataStatusEnum.ENABLE);
        accountFlow.setCreatedTime(LocalDateTime.now());
        accountFlow.setUpdateTime(LocalDateTime.now());

        return accountFlow;
    }

    public UserAccountFlowEntity createOperatingChargeAccountFlow(String userId,
                                                                  BigDecimal remainingBalance) {
        UserAccountFlowEntity accountFlow = createOrderFreezeAccountFlow(userId,remainingBalance);
        accountFlow.setExpenseType(ExpenseTypeEnum.OPERATE);
        accountFlow.setAmount(operatingCharge);

        return accountFlow;
    }

    public UserAccountFlowEntity createEstimatedFreightAccountFlow(String userId,
                                                                   BigDecimal remainingBalance) {
        UserAccountFlowEntity accountFlow = createOrderFreezeAccountFlow(userId,remainingBalance);
        accountFlow.setExpenseType(ExpenseTypeEnum.FREIGHT);
        accountFlow.setAmount(estimatedFreight);

        return accountFlow;
    }

    public UserAccountFlowEntity createRegistrationFreightAccountFlow(String userId,
                                                                      BigDecimal remainingBalance) {
        UserAccountFlowEntity accountFlow = createOrderFreezeAccountFlow(userId,remainingBalance);
        accountFlow.setExpenseType(ExpenseTypeEnum.REGISTRATION_FEE);
        accountFlow.setAmount(registrationFreight);

        return accountFlow;
    }

    public UserAccountFlowEntity createVatAccountFlow(String userId,
                                                                      BigDecimal remainingBalance) {
        UserAccountFlowEntity accountFlow = createOrderFreezeAccountFlow(userId,remainingBalance);
        accountFlow.setExpenseType(ExpenseTypeEnum.VAT);
        accountFlow.setAmount(vat);

        return accountFlow;
    }

    public UserAccountFlowEntity createVatHandlingFeeAccountFlow(String userId,
                                                      BigDecimal remainingBalance) {
        UserAccountFlowEntity accountFlow = createOrderFreezeAccountFlow(userId,remainingBalance);
        accountFlow.setExpenseType(ExpenseTypeEnum.VAT_HANDLING_FEE);
        accountFlow.setAmount(handlingFee);

        return accountFlow;
    }
}
